<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" isELIgnored="false" %>
<%@include file="taglib.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
</head>
<body>
    <div class="col-md-10 col-md-offset-1">
        <form class="form-horizontal" id="formData">
            <div class="form-group">
                <label for="ename" class="col-sm-1 control-label">uesrName</label>
                <div class="col-sm-3">
                    <input type="text" class="form-control" value="" name="ename" id="ename" placeholder="uesrName">
                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-offset-1 col-sm-3">
                    <div class="radio">
                        <label>
                            <input type="radio" name="ssex" value="男" checked>
                            男
                        </label>
                        <label>
                            <input type="radio" name="ssex" value="女">
                            女
                        </label>
                    </div>
                </div>
            </div>

            <div class="form-group">
                <label for="Salary" class="col-sm-1 control-label">Salary</label>
                <div class="col-sm-3" id="Salary">
                    <input type="number" class="form-control" value="" name="salary" placeholder="Salary">
                </div>
            </div>


            <div class="form-group">
                <label for="inputPassword3" class="col-sm-1 control-label">Password</label>
                <div class="col-sm-3">
                    <input type="password" class="form-control"  value="" name="pwd" id="inputPassword3" placeholder="Password">
                </div>
            </div>

            <div class="form-group">
                <label for="dno" class="col-sm-1 control-label">Dept</label>
                <div class="col-sm-3">
                    <select class="form-control" id="dno" name="dno">
                        <option value="0">请选择部门</option>
                    </select>
                </div>
            </div>

            <div class="form-group">
                <label for="birtday" class="col-sm-1 control-label">Birtday</label>
                <div class="col-sm-3">
                    <input type="date" class="form-control" value="" name="birtday" id="birtday">
                </div>
            </div>

            <div class="form-group">
                <div class="col-sm-offset-1 col-sm-3">
                    <input type="button" id="sumBtn" onclick="addEmp()" class="btn btn-default" value="提交"></input>
                </div>
            </div>
        </form>

    </div>

<script>
    function addEmp() {
        let emp = $("#formData").serialize();
        alert(typeof emp);
        $.ajax({
            url: "/emp/addEmp",
            type: "post",
            contentType: "application/json;charset=utf-8",
            data: emp,
            dataType: "json",
            success: function (result) {
                if (result == 1) {
                    alert("新增成功")
                } else {
                    alert("新增失败")
                }
            }
        })
    }


    $(function () {
        $.ajax({
            url:"/dept/getAllByDept",
            type:"get",
            dataType:"json",
            success:function (result) {
                for (let i in result){
                    $("#dno").append("<option value='"+result[i].dno+"'>"+result[i].dname+"</option>")
                }
            }
        })

    })




</script>
</body>
</html>